﻿using System;
using System.IO;
using System.Xml.Linq;

using Perseus.Data;
using Perseus.Plugins;

using Hetymine.Executioner.Commands;

namespace Hetymine.Executioner.Plugins.FTP {
    public class FTP : CommandPlugin, ILoader, IConfigurable<IniFile> {
        private IConfigurator<IniFile> _Configurator = null;

        public FTP() {
            this.PluginInfo = PluginInfo.FromAssembly(this.GetType().Assembly, "Blake Hancock");
        }

        public override ICommand InitializeCommand() {
            return new FTPCommand();
        }

        #region IPluginLoader Members
        public void Load() {
            string directory = AppDomain.CurrentDomain.BaseDirectory +
                "plugins" + Path.DirectorySeparatorChar +
                "FTP" + Path.DirectorySeparatorChar;
            if (!Directory.Exists(directory)) {
                Directory.CreateDirectory(directory);
            }
        }
        public void Unload() {
            // Clean up temp data.
            string directory = AppDomain.CurrentDomain.BaseDirectory +
                "plugins" + Path.DirectorySeparatorChar +
                "FTP" + Path.DirectorySeparatorChar;

            string[] files = Directory.GetFiles(directory);
            foreach (string s in files) {
                File.Delete(s);
            }
            Directory.Delete(directory);
        }
        #endregion

        #region IConfigurable Members
        public IConfigurator<IniFile> Configurator {
            get {
                if (this._Configurator == null) {
                    this._Configurator = new FTPConfig();
                }

                return this._Configurator;
            }
        }
        #endregion
    }
}
